package com.yuan.Service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yuan.Mapper.AddressBookMapper;
import com.yuan.Service.AddressBookService;
import com.yuan.context.BaseContext;
import com.yuan.entity.AddressBook;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.DeleteMapping;

import java.util.List;

@Service
public class AddressBookServiceImpl extends ServiceImpl<AddressBookMapper, AddressBook> implements AddressBookService {
    @Override
    public List<AddressBook> listSelf(AddressBook addressBook) {

        LambdaQueryWrapper<AddressBook> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(AddressBook::getUserId, addressBook.getUserId());
        List<AddressBook> list = list(queryWrapper);
        return list;
    }

    @Override
    public void addSelf(AddressBook addressBook) {

        addressBook.setUserId(BaseContext.getCurrentId());
        addressBook.setIsDefault(0);
        save(addressBook);
    }

    @Override
    public void setDefault(AddressBook addressBook) {
        AddressBook byId = getById(addressBook.getUserId());
        byId.setIsDefault(1);
          updateById(byId);

    }


}
